// pages/manage/check/check.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        mode: 'none',
        password: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    modalManagePasswordInput: function (e) {
        this.setData({
            password: e.detail.value
        })
    },

    manageBtnTap: function (e) {
        let that = this;
        const db = wx.cloud.database();
        db.collection('q_config').where({
            _id: 'passwords'
        }).get({
            success: res => {
                if (res.data[0]['manage_pass'] == that.data.password) {
                    that.setData({ password: '' })
                    if (e.currentTarget.dataset.index == 0) {
                        wx.redirectTo({
                          url: '../manage?mode=manage',
                        })
                    } else {
                        wx.redirectTo({
                            url: '../manage?mode=managelist',
                          })
                    }
                } else {
                    that.setData({ password: '' })
                    wx.showToast({
                        title: '密码错误',
                        icon: 'none'
                    })
                }
            },
            fail: res => {
                that.setData({ password: '' })
                wx.showToast({
                    title: '出错，请重试',
                    icon: 'none'
                })
            }
        })
    },
})